import axios from 'axios'
const request = axios.create({
    baseURL: '/api',
    timeout: 10000
})

//请求拦截
request.interceptors.request.use(
    (config) => {
        config.headers['Authorization'] = JSON.parse(localStorage.getItem('token')) || '' // 让每个请求携带自定义token 请根据实际情况自行修改
        config.headers['Content-Type'] = 'application/json;charset=utf-8'
       // config.headers['app-code'] = 'zcxm'//自定义请求头key value
        return config // 返回这个配置对象，如果没有返回，这个请求就不会发送出去
    },
    (error) => {
        return Promise.reject(error)
    }
)

//响应拦截
request.interceptors.response.use(
    (response) => {
        return response?.data
    },
    (error) => {
        return Promise.reject(error)
    }
)

export default request
